<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
	$(document).ready(
			function() {
				var url = "/kss/sectconfig/findall.do";
				//var url = "../sampledata/sect.txt";
				// prepare the data
				var source = {
					datatype : "json",
					datafields : [ {
						name : 'id',
						type : 'string'
					}, {
						name : 'se',
						type : 'string'
					}, {
						name : 'ct',
						type : 'string'
					}, {
						name : 'strategy',
						type : 'int'
					} ],
					id : 'id',
					url : url,
					sortcolumn : 'id',
					sortdirection : 'asc'
				};
				var dataAdapter = new $.jqx.dataAdapter(source);

				$("#jqxgrid").jqxGrid(
						{
							theme: "arctic",
							width : '100%',
							height : '100%',
							source : dataAdapter,
							sortable : true,
							columnsresize : true,
							selectionmode : 'checkbox',
							altrows : true,
							showtoolbar: true,
							rendertoolbar: function (toolbar) {
								var container = $("<div style='margin: 5px;'></div>");
								toolbar.append(container);
								container.append('<input id="addrowbutton" type="button" value="新增" />');
								container.append('<input id="deleterowbutton" type="button" value="删除" />');
								container.append('<input style="margin-left: 5px;" id="refreshbutton" type="button" value="刷新" />');
								$("#addrowbutton").jqxButton();
								$("#deleterowbutton").jqxButton();
								$("#refreshbutton").jqxButton();
							
								// create new row.
								$("#addrowbutton").on('click', function () {
									opendlg('新增', '/kss/sectconfig/getone.do?mode=add');	
								});

								// reloadtable.
								$("#refreshbutton").on('click', function () {
									$("#jqxgrid").jqxGrid('clearselection');
									source.sortcolumn = 'id';
									source.sortdirection = 'asc';
									$("#jqxgrid").jqxGrid('updatebounddata');
								});
								
								//delete row.
								$("#deleterowbutton").on('click', function () {
									var rowindexes = $("#jqxgrid").jqxGrid('getselectedrowindexes');
									if (rowindexes.length == 0) {
										alert('请选择删除条目');
										return;
									}									
									var params = "?del";
									var delrow = null;
									for (var i in rowindexes){
										delrow = $("#jqxgrid").jqxGrid('getrowdata', rowindexes[i]);
										params += '&ids=' + delrow.id;
									}									
									confirmdlg('确定删除吗？','/kss/sectconfig/del.do'+params,"#refreshbutton");
								});
							},
							columns : [
									{
										text : '#',
										sortable : false,
										filterable : false,
										editable : false,
										groupable : false,
										draggable : false,
										resizable : false,
										datafield : '',
										columntype : 'number',
										width : 50,
										cellsrenderer : function(row, column,
												value) {
											return "<div style='margin:4px;'>"
													+ (value + 1) + "</div>";
										}
									}, {
										text : 'id',
										datafield : 'id',
										width : '25%'
									}, {
										text : 'se',
										datafield : 'se',
										width : '25%'
									}, {
										text : 'ct',
										datafield : 'ct',
										width : '20%'
									}, {
										text : '策略(分钟)',
										datafield : 'strategy',
										width : '10%'
									}, {
										text : '编辑',
										datafield : 'Edit',
										width : '10%',
										columntype: 'button',
										cellsrenderer: function () {                     
											return "编辑";                  
										}, 
										buttonclick: function (row) {
											var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', row);
											opendlg('编辑', '/kss/sectconfig/getone.do?mode=save&id='+dataRecord.id);
										}
									} ]
						});
			});
</script>
</head>
<body>
  <div id="jqxgrid"></div>
</body>
</html>
